#! /bin/sh
echo "Swallow uWSGI Server Management"
USAGE="Usage: {start|stop|restart}" 
PID_FILE="/var/run/swallow.pid"

start()
{
	echo "Start uWSGI Server"
	uwsgi -s 127.0.0.1:8080 -w swallow --daemonize /var/log/swllow --pidfile=$PID_FILE
	echo "Done"
}

stop() 
{
	echo "Stop uWSGI Server"
	if [ -f $PID_FILE ]; then
		uwsgi --stop $PID_FILE
	fi
	echo "Done"
}

restart()
{
	echo "Restart uWSGI Server"
	stop;
	start;
}

if [ $# -gt 0 ]; then
        if [ $1 = "start" ]; then
		start;
        elif [ $1 = "stop" ]; then
		stop;
	elif [ $1 = "restart" ]; then
		restart;		
        else
        	echo "Invalid Option"
        	echo $USAGE
        fi
else
        echo $USAGE
fi
